package com.bawei.module_mine.utils

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import com.alibaba.android.arouter.launcher.ARouter

/**
 * 历史记录刷新管理器
 * 用于管理历史记录的实时刷新
 */
@SuppressLint("StaticFieldLeak")
object HistoryRefreshManager {
    
    private var currentHistoryActivity: Activity? = null
    
    /**
     * 注册当前的历史记录Activity
     */
    fun registerHistoryActivity(activity: Activity) {
        currentHistoryActivity = activity
    }
    
    /**
     * 注销历史记录Activity
     */
    fun unregisterHistoryActivity() {
        currentHistoryActivity = null
    }
    
    /**
     * 刷新历史记录
     * 如果当前有历史记录Activity在显示，则刷新它
     */
    fun refreshHistory() {
        currentHistoryActivity?.let { activity ->
            if (activity is com.bawei.module_mine.ui.HistoryActivity) {
                activity.refreshHistoryData()
            }
        }
    }
    
    /**
     * 跳转到历史记录页面
     */
    fun navigateToHistory(context: Context) {
        ARouter.getInstance()
            .build("/mine/HistoryActivity")
            .navigation(context)
    }
    
    /**
     * 跳转到历史记录页面并刷新
     */
    fun navigateToHistoryAndRefresh(context: Context) {
        val intent = Intent(context, com.bawei.module_mine.ui.HistoryActivity::class.java)
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
        context.startActivity(intent)
    }


} 